<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="腾讯安全实验室 c&#x2F;c++安全指南google c++ 代码规范 google c++ 编码规范 C&#x2F;C++代码规范（一）——文件结构、排版、命名规则 C&#x2F;C++代码规范（二）——表达式、常量、函数设计 C++effective读书笔记（待更新） 如何写出“颜值高”的代码？ @TOC">
<meta name="keywords" content="article">
<meta property="og:type" content="article">
<meta property="og:title" content="[笔记]c++Windows平台代码规范">
<meta property="og:url" content="https:&#x2F;&#x2F;shiverzm.github.io&#x2F;2022&#x2F;02&#x2F;20&#x2F;%5B%E7%AC%94%E8%AE%B0%5Dc++Windows%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83&#x2F;index.html">
<meta property="og:site_name" content="Shiver&#39;s BBBBlog">
<meta property="og:description" content="腾讯安全实验室 c&#x2F;c++安全指南google c++ 代码规范 google c++ 编码规范 C&#x2F;C++代码规范（一）——文件结构、排版、命名规则 C&#x2F;C++代码规范（二）——表达式、常量、函数设计 C++effective读书笔记（待更新） 如何写出“颜值高”的代码？ @TOC">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2022-02-20T14:54:50.000Z">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"always","offset":18,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Shiver'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://shiverzm.github.io/2022/02/20/[笔记]c++Windows平台代码规范/"/>





  <title>[笔记]c++Windows平台代码规范 | Shiver's BBBBlog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Shiver's BBBBlog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://shiverzm.github.io/2022/02/20/%5B%E7%AC%94%E8%AE%B0%5Dc++Windows%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Shiver">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Shiver's BBBBlog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">[笔记]c++Windows平台代码规范</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2022-02-20T22:53:09+08:00">
                2022-02-20
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2022/02/20/%5B%E7%AC%94%E8%AE%B0%5Dc++Windows%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/2022/02/20/%5B%E7%AC%94%E8%AE%B0%5Dc++Windows%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><a href="https://github.com/Tencent/secguide/blob/main/C,C++%E5%AE%89%E5%85%A8%E6%8C%87%E5%8D%97.md" target="_blank" rel="noopener">腾讯安全实验室 c/c++安全指南</a><br><a href="https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/" target="_blank" rel="noopener">google c++ 代码规范</a></p>
<p><a href="https://blog.csdn.net/xiexievv/article/details/50972809" target="_blank" rel="noopener">google c++ 编码规范</a></p>
<p><a href="https://blog.csdn.net/changyi9995/article/details/105714712" target="_blank" rel="noopener">C/C++代码规范（一）——文件结构、排版、命名规则</a></p>
<p><a href="https://blog.csdn.net/changyi9995/article/details/106043662" target="_blank" rel="noopener">C/C++代码规范（二）——表达式、常量、函数设计</a></p>
<p><a href="https://blog.csdn.net/vict_wang/article/details/81637048" target="_blank" rel="noopener">C++effective读书笔记（待更新）</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/350324541" target="_blank" rel="noopener">如何写出“颜值高”的代码？</a></p>
<p>@<a href="文章目录">TOC</a></p>
<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>不用谷歌的 使用微软风格<br>谷歌偏c风格 下划线很多 很难受</p>
<h1 id="1-文件结构"><a href="#1-文件结构" class="headerlink" title="1.文件结构"></a>1.文件结构</h1><h2 id="1-1-版权和版本的声明"><a href="#1-1-版权和版本的声明" class="headerlink" title="1.1 版权和版本的声明"></a>1.1 版权和版本的声明</h2><p>文件头 全使用英文 减少中文编码乱码问题</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">/****************************************************************</span><br><span class="line">* Copyright (c) 2021 by XXX Company</span><br><span class="line">* </span><br><span class="line">* file description：Export To Be DLL Implement</span><br><span class="line">* version：    1.0.0</span><br><span class="line">* author：     Shiver</span><br><span class="line">* time：       2021 / 05 / 31</span><br><span class="line">****************************************************************/</span><br></pre></td></tr></table></figure>

<h2 id="1-2-导出头文件命名-XXXAPI-h"><a href="#1-2-导出头文件命名-XXXAPI-h" class="headerlink" title="1.2 导出头文件命名 XXXAPI.h"></a>1.2 导出头文件命名 XXXAPI.h</h2><p>项目名+API+.h 作为导出dll 的对应头文件 统一格式方便查找</p>
<h2 id="1-3-常见项目结构"><a href="#1-3-常见项目结构" class="headerlink" title="1.3 常见项目结构"></a>1.3 常见项目结构</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-ProjectName</span><br><span class="line">--src</span><br><span class="line">--include</span><br><span class="line">--lib</span><br><span class="line">--bin</span><br><span class="line">--res</span><br></pre></td></tr></table></figure>

<blockquote>
<p>src        目录 存源码包括（*.cpp、*.h,<em>.cc,\</em>.hpp)<br>include 目录 存引入第三方库的 *.h文件<br>lib         目录 存引入第三方库的*.lib、*.a 、*.so （静态库和动态链接库)<br>bin        目录 存引入第三方库的*.dll  (动态库）<br>res       目录 存资源文件 例如*.jpg、*.icon</p>
</blockquote>
<h2 id="1-4-头文件-防止重复引入"><a href="#1-4-头文件-防止重复引入" class="headerlink" title="1.4 头文件 防止重复引入"></a>1.4 头文件 防止重复引入</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> XXX_H</span></span><br><span class="line"><span class="meta">#def XXX_H</span></span><br><span class="line"><span class="comment">// 主要内容</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br></pre></td></tr></table></figure>
<p>注：尽量不要使用#pragram once,不利于跨平台 貌似只有windows有这个宏</p>
<h2 id="1-5-导出接口命名"><a href="#1-5-导出接口命名" class="headerlink" title="1.5 导出接口命名"></a>1.5 导出接口命名</h2><p>格式：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">返回类型+“ ”+公司简称+“_”+模块简称+“_<span class="string">"+函数名(动+宾结构)+“（”+形参列表+“）”；</span></span><br></pre></td></tr></table></figure>
<p>例如：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">ByteDance_Decoder_CreateDecoder</span><span class="params">(<span class="keyword">int</span> a, <span class="keyword">int</span> b)</span></span>;</span><br></pre></td></tr></table></figure>

<p>当然导出的接口 自然有一些导出宏之类的 WINAPI 、extern “C”等 记得定义为宏 统一添加</p>
<h2 id="1-6-类和虚类命名"><a href="#1-6-类和虚类命名" class="headerlink" title="1.6 类和虚类命名"></a>1.6 类和虚类命名</h2><p>类(Class)以C开头，例如CFactory<br>虚类（接口Interface）以I开头，例如IFactory</p>
<h1 id="2-参数命名"><a href="#2-参数命名" class="headerlink" title="2.参数命名"></a>2.参数命名</h1><h2 id="2-1-局部变量"><a href="#2-1-局部变量" class="headerlink" title="2.1 局部变量"></a>2.1 局部变量</h2><p>int: nXXX   iXXX<br>指针:pXXX<br>char数组:szXXX<br>wchar_t数组:wszXXX</p>
<h2 id="2-2-静态变量"><a href="#2-2-静态变量" class="headerlink" title="2.2 静态变量"></a>2.2 静态变量</h2><p>s:static 静态变量<br>int:s_iXXX</p>
<h2 id="2-3-全局变量"><a href="#2-3-全局变量" class="headerlink" title="2.3 全局变量"></a>2.3 全局变量</h2><p>g:glogbal 全局变量<br>int: g_iXXX;</p>
<h2 id="2-4-成员变量"><a href="#2-4-成员变量" class="headerlink" title="2.4 成员变量"></a>2.4 成员变量</h2><p>m:member 成员<br>int:m_iXXX</p>
<table>
<thead>
<tr>
<th>变量类型</th>
<th>该类型变量的前缀</th>
<th>类型意义</th>
</tr>
</thead>
<tbody><tr>
<td>局部变量</td>
<td>无</td>
<td>例如 int类型 nXXX</td>
</tr>
<tr>
<td>静态变量</td>
<td>s_</td>
<td>例如 int类型 g_iXXX</td>
</tr>
<tr>
<td>全局变量</td>
<td>g_</td>
<td>例如 int类型 g_iXXX</td>
</tr>
<tr>
<td>成员变量</td>
<td>m_</td>
<td>例如 int类型 m_iXXX</td>
</tr>
</tbody></table>
<h2 id="2-5-常见变量命名"><a href="#2-5-常见变量命名" class="headerlink" title="2.5 常见变量命名"></a>2.5 常见变量命名</h2><p>表一 基本类型及前缀规范<br>|类型名定义|该类型变量的前缀|类型意义|<br>|–|–|–|<br>|int8_t    |n    |有符号的8bit整数|<br>|uint8_t    |n|    无符号的8bit整数|<br>|int16_t    |n|    有符号的16bit整数|<br>|uint16_t    |n|    无符号的16bit整数|<br>|int32_t    |n|    有符号的32bit整数|<br>|uint32_t    |n|无符号的32bit整数|<br>|int64_t    |n|    有符号的64bit整数|<br>|uint64_t    |n|    无符号的64bit整数|<br>|void    |v|    void类型|<br>|float32    |f|    32位浮点数|<br>|float64|<br>|double    |f|    64位浮点数|<br>|FILE*    |pf|    文件指针|<br>|char<em>|<br>|char[]    |sz|    字符指针,或者字符数组|<br>|char    |ch|    字符|<br>|wchar    |wch|    宽字符|<br>|wchar</em>|<br>|wchar[]    |wsz|    宽字节数组|<br>|string    |str|    字符串|<br>|wstring    |wstr|    宽字符串|<br>|vector    |vec|    vector容器|<br>|list    |list|    list容器|<br>|map    |map|    map容器|<br>|HANDLE    |h|    句柄|<br>|thread    |h|    线程句柄|<br>|DWORD    |dw|    双字|<br>|WORD    |w|    单字|<br>|bool/BOOL    |b|    布尔变量|<br>|函数指针    |pfunc|    函数指针|<br>|迭代器    |itr|    容器迭代器|</p>
<p>表2 变量属性公共前缀规则<br>|前缀    |前缀意义|<br>|–|–|<br>|arr|    数组类型变量|<br>|p    |指针类型变量|<br>|t    |自定义类型变量（自定义类型包括结构、联合、枚举型）|<br>|ap    |存放指针的数组|<br>|at    |存放自定义类型变量的数组|<br>|pa    |指向数组的指针|<br>|pp    |指向指针的指针变量（两维指针）|<br>|pt    |指向自定义类型的指针变量|</p>
<h1 id="3-函数命名"><a href="#3-函数命名" class="headerlink" title="3.函数命名"></a>3.函数命名</h1><h2 id="3-1大驼峰命名"><a href="#3-1大驼峰命名" class="headerlink" title="3.1大驼峰命名"></a>3.1大驼峰命名</h2><p>void ThisIsFunction();</p>
<h2 id="3-2-动词＋名词-结构"><a href="#3-2-动词＋名词-结构" class="headerlink" title="3.2 动词＋名词 结构"></a>3.2 动词＋名词 结构</h2><p>全局函数的名字应当使用“动词”或者“动词＋名词”（动宾词组）。类的成员函数应当只使用“动词”，被省略掉的名词就是对象本身。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">例如:</span><br><span class="line">InitModule()</span><br><span class="line">SetHeight()</span><br><span class="line">StartAction()</span><br><span class="line">StopAction()</span><br><span class="line">DestoryModule()</span><br></pre></td></tr></table></figure>

<h2 id="3-3-单个对象用-is-has-多个对象的集合用复数形态"><a href="#3-3-单个对象用-is-has-多个对象的集合用复数形态" class="headerlink" title="3.3 单个对象用 is has, 多个对象的集合用复数形态"></a>3.3 单个对象用 is has, 多个对象的集合用复数形态</h2><blockquote>
<p>比如<br>deleteFile，moveFiles，getChildren，单数复数表达的含义是不同的，file表示操作单个文件，files表示可以接受文件集合，children表示子节点不止一个。</p>
</blockquote>
<h2 id="3-4-用时态语态可以传达更多信息，增强可读性。"><a href="#3-4-用时态语态可以传达更多信息，增强可读性。" class="headerlink" title="3.4 用时态语态可以传达更多信息，增强可读性。"></a>3.4 用时态语态可以传达更多信息，增强可读性。</h2><p>对于正在发生的事情用进行时，doing;<br>对于一个做完的事情用过去式 did done。比如当状态发生变化的时候，<br>对于正在改变但是还没彻底变完，xxxChanging，<br>对于已经变了 xxxChanged 表示真的变了。</p>
<h1 id="4-代码规范"><a href="#4-代码规范" class="headerlink" title="4.代码规范"></a>4.代码规范</h1><h2 id="4-1-【内存申请原则】谁创建谁释放-平级作用域内释放"><a href="#4-1-【内存申请原则】谁创建谁释放-平级作用域内释放" class="headerlink" title="4.1 【内存申请原则】谁创建谁释放,平级作用域内释放"></a>4.1 【内存申请原则】谁创建谁释放,平级作用域内释放</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="keyword">int</span> *pNum = <span class="keyword">new</span> <span class="keyword">int</span>();</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">int</span> *pNum2 = <span class="keyword">new</span> <span class="keyword">int</span>();</span><br><span class="line">		<span class="keyword">delete</span> pNum2;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">delete</span> pNum;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="4-2-【结构体初始化】在创建结构体前-构造函数中初始化值"><a href="#4-2-【结构体初始化】在创建结构体前-构造函数中初始化值" class="headerlink" title="4.2 【结构体初始化】在创建结构体前/构造函数中初始化值"></a>4.2 【结构体初始化】在创建结构体前/构造函数中初始化值</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">test</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">  <span class="keyword">int</span> a;</span><br><span class="line">  <span class="keyword">int</span> b;</span><br><span class="line">  test()&#123;</span><br><span class="line">   a = <span class="number">0</span>;</span><br><span class="line">   b = <span class="number">0</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">test</span> <span class="title">testa</span>;</span></span><br><span class="line"><span class="built_in">memset</span>(testa,<span class="number">0</span>,<span class="keyword">sizeof</span>(testa));</span><br></pre></td></tr></table></figure>
<p>声明初始化以及构造初始化 有利于避免野指针。</p>
<h1 id="5-代码格式"><a href="#5-代码格式" class="headerlink" title="5.代码格式"></a>5.代码格式</h1><h2 id="5-1-一行只申明一个变量-且声明后马上初始化"><a href="#5-1-一行只申明一个变量-且声明后马上初始化" class="headerlink" title="5.1 一行只申明一个变量,且声明后马上初始化"></a>5.1 一行只申明一个变量,且声明后马上初始化</h2><p>错误范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a,b,c;</span><br></pre></td></tr></table></figure>
<p>正确范例:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> b = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> c = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">char</span> *buffer = <span class="keyword">new</span> <span class="keyword">char</span>[<span class="number">260</span>];</span><br><span class="line"><span class="built_in">memset</span>(buffer,<span class="number">0</span>,<span class="number">260</span>);</span><br></pre></td></tr></table></figure>
<h2 id="5-2-代码块之间用-多使用换行-分隔"><a href="#5-2-代码块之间用-多使用换行-分隔" class="headerlink" title="5.2 代码块之间用 多使用换行 分隔"></a>5.2 代码块之间用 多使用换行 分隔</h2><p>错误范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a;</span><br><span class="line"><span class="keyword">int</span> b;</span><br><span class="line"><span class="keyword">int</span> c;</span><br><span class="line"><span class="keyword">if</span>(b==<span class="number">2</span>)&#123;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>正确范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a;</span><br><span class="line"><span class="keyword">int</span> b;</span><br><span class="line"><span class="keyword">int</span> c;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(b == <span class="number">2</span>)</span><br><span class="line">&#123;</span><br><span class="line"> ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-3-操作符与变量之间-多使用-空格-分隔"><a href="#5-3-操作符与变量之间-多使用-空格-分隔" class="headerlink" title="5.3 操作符与变量之间 多使用 空格 分隔"></a>5.3 操作符与变量之间 多使用 空格 分隔</h2><p>错误范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(b==<span class="number">0</span>)&#123;...&#125;</span><br><span class="line">a&gt;b?<span class="number">0</span>:<span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<p>正确范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(b == <span class="number">0</span>)&#123;</span><br><span class="line">...</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">a &gt; b ? <span class="number">0</span> : <span class="number">1</span>;</span><br></pre></td></tr></table></figure>
<h2 id="5-4-判断语句和循环语句-内容必须用-包裹"><a href="#5-4-判断语句和循环语句-内容必须用-包裹" class="headerlink" title="5.4 判断语句和循环语句 内容必须用{}包裹"></a>5.4 判断语句和循环语句 内容必须用{}包裹</h2><p>错误范例:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(a==<span class="number">0</span>) <span class="keyword">return</span> a;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>) <span class="keyword">return</span> <span class="number">0</span>;</span><br></pre></td></tr></table></figure>
<p>正确范例:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(a==<span class="number">0</span>)</span><br><span class="line">&#123;</span><br><span class="line"> ...   </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-5-包裹的内容必须有层次感-通过一层一个tab"><a href="#5-5-包裹的内容必须有层次感-通过一层一个tab" class="headerlink" title="5.5 {}包裹的内容必须有层次感 通过一层一个tab"></a>5.5 {}包裹的内容必须有层次感 通过一层一个tab</h2><p>错误范例：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(a==<span class="number">0</span>)</span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">return</span> a;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>正确范例:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(a == <span class="number">0</span>) <span class="comment">//1 层</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>) <span class="comment">// 2层</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="number">0</span>;<span class="comment">//3 层</span></span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">return</span> a;<span class="comment">//2层</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="6-常见通俗规定"><a href="#6-常见通俗规定" class="headerlink" title="6.常见通俗规定"></a>6.常见通俗规定</h1><h2 id="6-1-函数形参顺序-先dst-后src"><a href="#6-1-函数形参顺序-先dst-后src" class="headerlink" title="6.1 函数形参顺序  先dst,后src"></a>6.1 函数形参顺序  先dst,后src</h2><p>void *memcpy(void *destin, void *source, unsigned n);</p>
<h2 id="6-2-长循环放内部，短循环放外部"><a href="#6-2-长循环放内部，短循环放外部" class="headerlink" title="6.2 长循环放内部，短循环放外部"></a>6.2 长循环放内部，短循环放外部</h2><p>在多重循环中，如果有可能，应当将最长的循环放在最内层，最短的循环放在最外层，以减少CPU跨切循环层的次数。例如示例4-4(b)的效率比示例4-4(a)的高。</p>
<h2 id="6-3-使用const-static-代替-define"><a href="#6-3-使用const-static-代替-define" class="headerlink" title="6.3 使用const static 代替 #define"></a>6.3 使用const static 代替 #define</h2><h2 id="6-4-执行命令时-文件路径-记得用转义字符-“-“圈起来路径"><a href="#6-4-执行命令时-文件路径-记得用转义字符-“-“圈起来路径" class="headerlink" title="6.4 执行命令时 文件路径 记得用转义字符 \“ \“圈起来路径"></a>6.4 执行命令时 文件路径 记得用转义字符 \“ \“圈起来路径</h2><h2 id="6-5-路径中的斜杠-默认使用反斜杠"><a href="#6-5-路径中的斜杠-默认使用反斜杠" class="headerlink" title="6.5 路径中的斜杠 默认使用反斜杠 /"></a>6.5 路径中的斜杠 默认使用反斜杠 /</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">windows  \\等于/</span><br><span class="line">linux  /就是/</span><br></pre></td></tr></table></figure>

<h2 id="6-6-四个空格等于一个tab-但一般用4个空格-一个tab某平台等于8个空格"><a href="#6-6-四个空格等于一个tab-但一般用4个空格-一个tab某平台等于8个空格" class="headerlink" title="6.6 四个空格等于一个tab 但一般用4个空格 一个tab某平台等于8个空格"></a>6.6 四个空格等于一个tab 但一般用4个空格 一个tab某平台等于8个空格</h2><h1 id="7-常见埋坑操作"><a href="#7-常见埋坑操作" class="headerlink" title="7.常见埋坑操作"></a>7.常见埋坑操作</h1><h2 id="7-1-文件路径"><a href="#7-1-文件路径" class="headerlink" title="7.1 文件路径"></a>7.1 文件路径</h2><p>1.文件路径字符串请用””圈起来，避免有空格情况以及部分系统无法识别相关命令<br>2.文件路径字符串如果有中文请使用Unicode编码</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>if it helps for you,thanks for your donation !</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="Shiver 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Shiver 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/10/27/hello-world/" rel="next" title="github pages+hexo搭建个人博客">
                <i class="fa fa-chevron-left"></i> github pages+hexo搭建个人博客
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div onclick="showGitment()" id="gitment-display-button">显示 Gitment 评论</div>
        <div id="gitment-container" style="display:none"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="Shiver" />
            
              <p class="site-author-name" itemprop="name">Shiver</p>
              <p class="site-description motion-element" itemprop="description"><a href="http://112.74.51.46:9000/" target="_blank" rel="noopener">website blog</a></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives%7C%7Carchive">
              
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/ShiverZm" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://112.74.51.46:9000/" target="_blank" title="myblogsite">
                      
                        <i class="fa fa-fw fa-firefox"></i>myblogsite</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://112.74.51.46:9000/" title="daniublog" target="_blank">daniublog</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#1-文件结构"><span class="nav-number">2.</span> <span class="nav-text">1.文件结构</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-版权和版本的声明"><span class="nav-number">2.1.</span> <span class="nav-text">1.1 版权和版本的声明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-导出头文件命名-XXXAPI-h"><span class="nav-number">2.2.</span> <span class="nav-text">1.2 导出头文件命名 XXXAPI.h</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-常见项目结构"><span class="nav-number">2.3.</span> <span class="nav-text">1.3 常见项目结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-4-头文件-防止重复引入"><span class="nav-number">2.4.</span> <span class="nav-text">1.4 头文件 防止重复引入</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-5-导出接口命名"><span class="nav-number">2.5.</span> <span class="nav-text">1.5 导出接口命名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-6-类和虚类命名"><span class="nav-number">2.6.</span> <span class="nav-text">1.6 类和虚类命名</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-参数命名"><span class="nav-number">3.</span> <span class="nav-text">2.参数命名</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-局部变量"><span class="nav-number">3.1.</span> <span class="nav-text">2.1 局部变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-静态变量"><span class="nav-number">3.2.</span> <span class="nav-text">2.2 静态变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-全局变量"><span class="nav-number">3.3.</span> <span class="nav-text">2.3 全局变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-4-成员变量"><span class="nav-number">3.4.</span> <span class="nav-text">2.4 成员变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-5-常见变量命名"><span class="nav-number">3.5.</span> <span class="nav-text">2.5 常见变量命名</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-函数命名"><span class="nav-number">4.</span> <span class="nav-text">3.函数命名</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1大驼峰命名"><span class="nav-number">4.1.</span> <span class="nav-text">3.1大驼峰命名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-动词＋名词-结构"><span class="nav-number">4.2.</span> <span class="nav-text">3.2 动词＋名词 结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-单个对象用-is-has-多个对象的集合用复数形态"><span class="nav-number">4.3.</span> <span class="nav-text">3.3 单个对象用 is has, 多个对象的集合用复数形态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-4-用时态语态可以传达更多信息，增强可读性。"><span class="nav-number">4.4.</span> <span class="nav-text">3.4 用时态语态可以传达更多信息，增强可读性。</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-代码规范"><span class="nav-number">5.</span> <span class="nav-text">4.代码规范</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-【内存申请原则】谁创建谁释放-平级作用域内释放"><span class="nav-number">5.1.</span> <span class="nav-text">4.1 【内存申请原则】谁创建谁释放,平级作用域内释放</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-【结构体初始化】在创建结构体前-构造函数中初始化值"><span class="nav-number">5.2.</span> <span class="nav-text">4.2 【结构体初始化】在创建结构体前/构造函数中初始化值</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-代码格式"><span class="nav-number">6.</span> <span class="nav-text">5.代码格式</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#5-1-一行只申明一个变量-且声明后马上初始化"><span class="nav-number">6.1.</span> <span class="nav-text">5.1 一行只申明一个变量,且声明后马上初始化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-2-代码块之间用-多使用换行-分隔"><span class="nav-number">6.2.</span> <span class="nav-text">5.2 代码块之间用 多使用换行 分隔</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-3-操作符与变量之间-多使用-空格-分隔"><span class="nav-number">6.3.</span> <span class="nav-text">5.3 操作符与变量之间 多使用 空格 分隔</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-4-判断语句和循环语句-内容必须用-包裹"><span class="nav-number">6.4.</span> <span class="nav-text">5.4 判断语句和循环语句 内容必须用{}包裹</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-5-包裹的内容必须有层次感-通过一层一个tab"><span class="nav-number">6.5.</span> <span class="nav-text">5.5 {}包裹的内容必须有层次感 通过一层一个tab</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-常见通俗规定"><span class="nav-number">7.</span> <span class="nav-text">6.常见通俗规定</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#6-1-函数形参顺序-先dst-后src"><span class="nav-number">7.1.</span> <span class="nav-text">6.1 函数形参顺序  先dst,后src</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-长循环放内部，短循环放外部"><span class="nav-number">7.2.</span> <span class="nav-text">6.2 长循环放内部，短循环放外部</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-3-使用const-static-代替-define"><span class="nav-number">7.3.</span> <span class="nav-text">6.3 使用const static 代替 #define</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-4-执行命令时-文件路径-记得用转义字符-“-“圈起来路径"><span class="nav-number">7.4.</span> <span class="nav-text">6.4 执行命令时 文件路径 记得用转义字符 \“ \“圈起来路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-5-路径中的斜杠-默认使用反斜杠"><span class="nav-number">7.5.</span> <span class="nav-text">6.5 路径中的斜杠 默认使用反斜杠 /</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-6-四个空格等于一个tab-但一般用4个空格-一个tab某平台等于8个空格"><span class="nav-number">7.6.</span> <span class="nav-text">6.6 四个空格等于一个tab 但一般用4个空格 一个tab某平台等于8个空格</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-常见埋坑操作"><span class="nav-number">8.</span> <span class="nav-text">7.常见埋坑操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#7-1-文件路径"><span class="nav-number">8.1.</span> <span class="nav-text">7.1 文件路径</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">9.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Shiver</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  






  
  







  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/canvas_lines.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    
      <style>
        a.gitment-editor-footer-tip { display: none; }
        .gitment-container.gitment-footer-container { display: none; }
      </style>
    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            id: window.location.pathname, 
            owner: 'ShiverZm',
            repo: 'https://github.com/ShiverZm/ShiverZm.github.io.git',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: '56d416235fbde886b35fb57161fc0093aeddcf63',
            
                client_id: 'd2a19344e8bb9a51b63f'
            }});
        gitment.render('gitment-container');
      }

      
      function showGitment(){
        document.getElementById("gitment-display-button").style.display = "none";
        document.getElementById("gitment-container").style.display = "block";
        renderGitment();
      }
      
      </script>
    







  <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
  <script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
  <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
   <script type="text/javascript">
        var gitalk = new Gitalk({
          clientID: '',
          clientSecret: '',
          repo: 'shiverzm.github.io',
          owner: '',
          admin: [''],
          id: md5(window.location.pathname),
          distractionFreeMode: ''
        })
        gitalk.render('gitalk-container')
       </script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>
